<!--<%&#45;&#45;-->
<!--Created by IntelliJ IDEA.-->
<!--User: 86185-->
<!--Date: 2024/1/12-->
<!--Time: 9:11-->
<!--To change this template use File | Settings | File Templates.-->
<!--&#45;&#45;%>-->
<!--<%@ page contentType="text/html;charset=UTF-8" language="java" %>-->
<html>
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="../../scripts/boot.js" type="text/javascript"></script>

  <script>
      function check(frm) {
          console.log("frm")
          console.log(typeof frm)
          //所有的标签（html、xml）在js世界都是一个个对象
          var username = frm.acname.value;
          var password = frm.passwd.value;
          if (username == "" || password == "") {
              alert("账户或密码不能为空")
              return false;
          }
          return true;
      }
  </script>
</head>
<body >
<div class="container">
  <div class="row clearfix">
    <div class="col-md-12 column">
      <label id="ts" style="color:red"></label>
      <form id="form1" role="form" action="javascript:void(0)" onsubmit="return check(this)" style="postion:absolute;">
        <div class="form-group">
          <label for="oldpassword">原密码</label>
          <input type="password" class="oldpassword" id="oldpassword" name="oldpassword" />
        </div>
        <div class="form-group">
          <label for="password">新密码</label>
          <input type="password" class="password" id="password" name="password"/>
        </div>
        <div class="form-group">
          <label for="password2">确认密码</label>
          <input type="password" class="password2" id="password2" name="password2"/>
        </div>
        <button type="button" class="btn btn-default" onclick="changewd()">修改密码</button>
      </form>
    </div>
  </div>
</div>

</body>
</html>
<script>
  var httpreq=null;
  var ts=document.getElementById("ts")
  function changewd(){
    var oldpassword=document.getElementById("oldpassword").value;
    var password=document.getElementById("password").value;
    var password2=document.getElementById("password2").value;
    if(oldpassword==""||password==""||password2==""){
      ts.innerHTML="密码不为空"
      return
    }
    if(password!=password2){
      ts.innerHTML="密码不一致"
      return
    }
    if(httpreq==null) httpreq=new XMLHttpRequest()
    httpreq.onreadystatechange=function (){
      if(httpreq.readyState==4&&httpreq.status==200){
        //弹出请求返回的数据
       var res=httpreq.responseText;
       if(res.indexOf("olderror")!=-1) {
         ts.innerHTML = "原密码错误"
       }else if(res.indexOf("FAIL")!=-1){
         ts.innerHTML = "修改失败"
       }else{
         ts.innerHTML="登录成功，稍后带你到主页...."
         setTimeout("window.location.href='frame/frame1/cindex.html'",1000)
       }
      }
    }

   // httpreq.open("get","adminaction?method=changewd&oldpassword="+oldpassword+"&password="+password)
   // httpreq.open("get","customeraction?method=changewd&oldpassword="+oldpassword+"&password="+password)
   //  httpreq.send()

      $.ajax(
          {

              url:"customer/changewd",
              data:{password:password,oldpassword:oldpassword},
              success:function(result){
                  //alert(result);
                  if(result.indexOf("success")!=-1){
                      window.location.href="frame/frame1/cindex.html";
                  }else{
                      $("#ts").html("无效的帐号或密码");
                  }
              }
          }
      );
  }

  // function message() {
  //     var form = new mini.Form("form1");// new  FormData()
  //     $.ajax({
  //         url:"customer/getinfo",
  //         // data:{method:"getinfo"},
  //         success: function (text) {
  //             console.log(text)
  //
  //             form.setData(text);
  //             // message()
  //         },
  //         error: function () {
  //         }
  //     })
  //
  // }
  //
  // // 页面加载完成后调用 getInfo 函数
  // $(document).ready(function() {
  //     message()
  // });
</script>
